<template>
  <van-form @submit="edit">
    <h2>修改租赁信息</h2>
    <van-field
        v-model="name"
        name="租赁者"
        label="租赁者"
        placeholder="租赁者"
        :rules="[{ required: true, message: '请填写租赁者' }]"
    />
    <van-field
        v-model="zlsj"
        name="租赁时间"
        label="租赁时间"
        placeholder="租赁时间"
        :rules="[{ required: true, message: '请填写租赁时间' }]"
    />
    <van-field
        v-model="ip"
        name="服务器IP"
        label="服务器IP"
        placeholder="服务器IP"
        :rules="[{ required: true, message: '请填写服务器IP' }]"
    />
    <van-field
        v-model="zlbz"
        name="租赁备注"
        label="租赁备注"
        placeholder="租赁备注"
        :rules="[{ required: false, message: '请填写租赁备注' }]"
    />
    <div style="margin: 16px;" class="text-center visible-lg visible-md">
      <van-button round type="info" native-type="submit" style="width: 30%;">修改</van-button>
    </div>
    <div style="margin: 16px;" class="text-center visible-sm visible-xs">
      <van-button round type="info" native-type="submit" style="width: 70%;">修改</van-button>
    </div>
  </van-form>
</template>

<script>
import qs from 'qs'
import {setServerLease} from "../../utils/api";
export default {
  name: "ServerLeaseEdit",
  created() {
    let { ip,zlsj,name,zlbz,lease_id } = this.$route.params.valuse;
    this.ip=ip;
    this.zlsj=zlsj;
    this.name=name;
    this.zlbz=zlbz;
    this.id=lease_id;
  },
  data(){
    return {
      ip:'',
      zlsj:'',
      name:'',
      zlbz:'',
      id:''
    }
  },
  methods:{
    edit(){
      this.$dialog.confirm({
        message: '您确定要修改了吗？',
      }).then(() => {
        setServerLease(qs.stringify({id:this.id,ip:this.ip,zlsj:this.zlsj,zlyhm:this.name,zlbz:this.zlbz})).then(respose=>{
          if(respose.status===200){
            this.$toast.success("修改成功");
            this.$router.go(-1);
          }else{
            this.$toast.fail("修改失败")
          }
        }).catch(error=>{
          console.log(error);
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>

</style>